using Admin2025.Application.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Admin2025.Application.EventHandlers;

//用户密码修改事件处理器 - 安全审计

public class UserPasswordChangedSecurityHandler : INotificationHandler<UserPasswordChangedNotification>
{
    private readonly ILogger<UserPasswordChangedSecurityHandler> _logger;
    public UserPasswordChangedSecurityHandler(ILogger<UserPasswordChangedSecurityHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(UserPasswordChangedNotification notification, CancellationToken cancellationToken)
    {
        var passwordEvent = notification.UserPasswordChangedEvent;

        _logger.LogInformation("安全审计：用户密码已修改-事件ID={EventID}，用户ID={UserId}，用户名={Username}，修改者={ChangedBy}，修改时间={OccurredOn}",
            passwordEvent.EventId, passwordEvent.UserId, passwordEvent.Username, passwordEvent.ChangedBy, passwordEvent.OccurredOn);

        //这里可以
        // 1.记录到安全审计日志
        // 2.发送邮件通知
        // 3.触发安全检查
        await Task.CompletedTask;
    }
}